# coding:utf-8

from ftplib import FTP
from datetime import date

def upload_ams_log(venue_id):
    ftp_server = '115.182.69.8'
    #ftp_server = '47.88.24.35'
    username = 'qujianning'
    password = 'Ko0f3Hf9Jh31Q'
    bufsize = 1024
    remotepath = "prj/tdm/log"
    localpath = r'D:\Program Files (x86)\Attend\AttendManage\log\attend.log'
    date_path = date.today().isoformat()
    remote_fname = 'attend_%s.log' % venue_id

    ftp = FTP()
    ftp.set_debuglevel(2)
    ftp.connect(ftp_server, 21)
    ftp.login(username, password)
    ftp.cwd(remotepath)
    try:
        ftp.mkd(date_path)
    except:
        print 'the dir is exists %s' % date_path
    ftp.cwd(date_path)
    fp = open(localpath,'rb')
    ftp.storbinary('STOR '+ remote_fname, fp, bufsize)
    ftp.set_debuglevel(0)
    fp.close()
    ftp.quit()

if __name__ == '__main__':
    upload_ams_log(venue_id='asdf')